package com.frxuexi.park2304.notice

import com.frxuexi.lib_base.http.ApiService
import com.frxuexi.lib_base.mvi.BaseViewModel
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject

@HiltViewModel
class NoticeViewModel @Inject constructor(val apiService: ApiService):BaseViewModel<NoticeIntent>() {
    override fun handleIntent(it: NoticeIntent) {
        when(it){
            is NoticeIntent.getNotices->pagerRequest { NoticeDataSource(apiService) }
            is NoticeIntent.addNotice->httpRequest(apiService.addNotice(toBody(it.item)))
            is NoticeIntent.getNoticeList->httpRequest(apiService.getNotices(it.page))
            is NoticeIntent.getNoticeById->httpRequest(apiService.getNoticeById(it.id))
        }
    }
}